package com.dbb.trade.entity.shipment;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.dbb.trade.entity.IdEntity;
import com.dbb.trade.entity.product.Suit;
/**
 * 箱规包括长宽高重量等
 * @author Administrator
 *
 */
@Entity
public class Ctn extends IdEntity{
	
	private static final Integer CM_M = 1000000;
	private List<Suit> suits;
	private Float length;
	private Float width;
	private Float high;
	private Float netWeight;
	private Float grossWeight;
	private Integer prs;
	
	public Ctn() {
		
	}
	
	public Ctn(Integer prs, Float length,
			Float width, Float high, Float netWeight, Float grossWeight) {
		super();
		this.prs = prs;
		this.length = length;
		this.width = width;
		this.high = high;
		this.netWeight = netWeight;
		this.grossWeight = grossWeight;
	}

	public Ctn(Integer prs) {
		this.prs = prs;
	}
	public Ctn(int prs, Suit s) {
		this.prs = prs;
		this.suits = new ArrayList<Suit>();
		suits.add(s);
	}
	
	public Ctn(int prs, List<Suit> suits) {
		this.prs = prs;
		this.suits = suits;
	}

	public Ctn(Suit ...suit) {
		this.prs = suit[0].getColorSizesPrs();
		this.suits = new ArrayList<Suit>();
		for(Suit s : suit) {
			suits.add(s);
		}
	}

	public Float getLength() {
		return length;
	}

	public void setLength(Float length) {
		this.length = length;
	}

	public Float getWidth() {
		return width;
	}

	public void setWidth(Float width) {
		this.width = width;
	}

	public Float getHigh() {
		return high;
	}

	public void setHigh(Float high) {
		this.high = high;
	}

	public void setGrossWeight(Float grossWeight) {
		this.grossWeight = grossWeight;
	}

	public Float getNetWeight() {
		return netWeight;
	}
	public void setNetWeight(Float netWeight) {
		this.netWeight = netWeight;
	}
	public Float getGrossWeight() {
		return grossWeight;
	}
	public void setGrossweight(Float grossweight) {
		this.grossWeight = grossweight;
	}
	
	@Transient
	public Float getCbm() {
		return (length * high * width) / CM_M;
	}
	
	public Integer getPrs() {
		return prs;
	}

	public void setPrs(Integer prs) {
		this.prs = prs;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "CTN_ID")
	public List<Suit> getSuits() {
		return suits;
	}

	public void setSuits(List<Suit> suits) {
		this.suits = suits;
	}

	public void addSuit(Suit s) {
		if(this.suits == null) {
			suits = new ArrayList<Suit>();
		}
		suits.add(s);
	}
	@Transient
	public Integer getSuitPrs() {
		return suits.get(0).getTotalPairs();
	}
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}
